package isPalindrome;

public class Solution {
    public boolean isPalindrome(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(check(s.charAt(i))) {
                sb.append(get(s.charAt(i)));
            }
        }
        String t = sb.toString();
        return t.equals(sb.reverse().toString());
    }
    private char get(char c) {
        // 只有大写字母转换成小写字母
        // 'a' = 'A' + 'a' - 'A';
        // 'x' = ''
        if(c>='A'&&c<='Z')return (char)(c + 'a' - 'A');
        return c;
    }
    private boolean check(char c) {
        if(c>='0'&&c<='9')return true;
        if(c>='a'&&c<='z')return true;
        if(c>='A'&&c<='Z')return true;
        return false;
    }
}
